(function(global, factory) {
	typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
		typeof define === 'function' && define.amd ? define(factory) :
		(global = global || self, global.Navigator = factory());
}(this, function() {
	'use strict';
	return function(obj){
		if(!obj.el){
			throw new Error('必须有el属性才能执行');
		}
		let parentNode = document.querySelector(obj.el);
		parentNode.classList.add('da-nav');
		if(obj.logo){
			let logo = document.createElement('div');
			logo.classList.add('da-logo')
			parentNode.appendChild(logo);
			let logoImg = document.createElement('img');
			logoImg.src=obj.logo;
			logo.appendChild(logoImg);
		}
		if(obj.navList){			
			let listBox = document.createElement('div');
			listBox.classList.add('da-nav-list');
			let slider = document.createElement('i');
			listBox.appendChild(slider);
			listBox.addEventListener('mouseout',function(){
				if(slider.offsetWidth!==0){
					slider.style.width = "0px";
				}
			})
			let ul = document.createElement('ul');
			listBox.appendChild(ul);
			parentNode.appendChild(listBox);
			obj.navList.forEach(function(item){
				let li = document.createElement('li');
				ul.appendChild(li);
				let a = document.createElement('a');
				a.innerHTML = item.title;
				a.href="javascript:;";
				li.appendChild(a);
				li.addEventListener('mouseover',function(){
					slider.style.left = a.offsetLeft+"px";
					slider.style.width = a.offsetWidth+"px";
					a.style.color="#55AAFF";
				});
				li.addEventListener('mouseout',function(){
					a.style.color="rgb(100, 119, 135)";
				})
				if(item.click){
					a.addEventListener('click',item.click);
				}
			});
		}
		if(obj.portrait){
			let portrait = document.createElement('div');
			portrait.classList.add('da-portrait');
			portrait.style.backgroundImage = "url("+obj.portrait.url+")"
			parentNode.appendChild(portrait);
			if(obj.portrait.menu){
				let menu = document.createElement('div');
				menu.style.height = "0px";
				menu.classList.add('da-menu');
				parentNode.appendChild(menu);
				let ul = document.createElement('ul');
				menu.appendChild(ul);
				obj.portrait.menu.forEach(function(item){
					let li = document.createElement('li');
					ul.appendChild(li);
					let a = document.createElement('a');
					a.innerHTML = item.title;
					a.href=item.href;
					li.appendChild(a);
				});
				portrait.addEventListener('click',function(){
					if(menu.offsetHeight===0){
						menu.style.height = "auto";
						menu.style.paddingTop = "12px";
						menu.style.paddingBottom = "12px";
					}else{
						menu.style.height = "0px";
						menu.style.paddingTop = "0px";
						menu.style.paddingBottom = "0px";
					}
				})
				let li = document.createElement('li');
				ul.appendChild(li);
				let a = document.createElement('a');
				a.innerHTML = "退出";
				a.href="exit.action";
				li.appendChild(a);
			}
		}
	}
}));